﻿using CaclLib.Handle;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CalcScore1._0
{
    public partial class CaclScore : Form
    {
        public CaclScore()
        {
            InitializeComponent();
        }

        private void btnExport_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.Title = "C# Corner Open File Dialog";
            openFileDialog1.InitialDirectory = @"c:\";
            openFileDialog1.Filter = "All files (*.*)|*.*|xls files (*.xlsx)|*.xls";
            //openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
              
                //System.IO.Path.GetFullPath(openFileDialog1.FileName); //绝对路径
               string extendName= System.IO.Path.GetExtension(openFileDialog1.FileName); //文件扩展名
                if (extendName == ".xls" || extendName == ".xlsx")
                {
                    textBox1.Text = System.IO.Path.GetFileName(openFileDialog1.FileName);
                    textBox1.ForeColor = Color.Green;
                    string path= System.IO.Path.GetFullPath(openFileDialog1.FileName);
                    DataTable dt=  ExcelHelper.Import_Excel(path);
                    this.LoadDataGridView.DataSource=dt;
                }
                else 
                {
                    textBox1.Text = "文件格式不正确";
                    textBox1.ForeColor = Color.Red;
                }

                //System.IO.Path.GetFileNameWithoutExtension(openFileDialog1.FileName); //文件名没有扩展名
                //System.IO.Path.GetFileName(openFileDialog1.FileName); //得到文件
                //System.IO.Path.GetDirectoryName(openFileDialog1.FileName); //得到路径
            }
        }
    }
}
